﻿//排班管理详细计划清单
Ext.namespace('FantastPlatform', 'FantastPlatform.UI');
FantastPlatform.UI.AddImageGrid = function (config) {
    Ext.apply(this, config);
    var gridUrl = this.url;
    var fileStore = new Ext.data.Store({
        proxy: new Ext.data.HttpProxy({
            url: gridUrl
        }),
        reader: new Ext.data.JsonReader({
            root: 'topics',
            totalProperty: 'totalCount',
            id: 'Id',
            fields: ['Id', 'Name', 'Description', 'ImagePath']
        }),
        remoteStore: true
    });
    this.store = fileStore;
    var paperBar = new FantastPlatform.Common.PapeToolBar({
        store: fileStore,
        defaultNum: 8
    });
    this.paperBar = paperBar;
    this.bbar = paperBar;
    this.pageNumber = paperBar.pageSize;

    var nm = new Ext.grid.RowNumberer();
    var sm = new Ext.grid.CheckboxSelectionModel();

    this.columns = [nm, sm, {
        header: 'Id',
        dataIndex: 'Id',
        hidden: true
    },
    {
        header: '名称',
        dataIndex: 'Name',
        width: 60
    },
    {
        header: '描述',
        dataIndex: 'Description',
        width: 150
    }, {
        header: '缩略图',
        dataIndex: 'ImagePath',
        sortable: true,
        renderer: function icon(val) {
            return '<img width=16px height=16px  src="' + val + '"/>'
        }
    }, {
        header: '查看大图',
        dataIndex: 'ImagePath',
        sortable: true,
        renderer: function qtips(val, p, record) {
            return '<span style="display:table;width=100%;" qtip=\'<img width=190px height=190px src="' + val + '">\'>' + record.data.Name + '</span>'
        }
    }
    ];
    FantastPlatform.UI.AddImageGrid.superclass.constructor.call(this, {
        loadMask: { msg: '正在加载数据...' },
        sm: sm
    });
};
Ext.extend(FantastPlatform.UI.AddImageGrid, Ext.grid.GridPanel, {
    onRender: function (ct, position) {
        FantastPlatform.UI.AddImageGrid.superclass.onRender.call(this, ct, position);
    },
    //添加商业店铺图片
    onAddBusinessImageClick: function (houseId) {
        var id = GUID();
        currtWind = openWind('../InfoCollection/AddBusinessImageForm.aspx?houseId=' + houseId, id, '添加商业店铺图片', 502, 500, 'new_tab')
    },
    //添加小区院落图片
    onAddHouseDistrictClick: function (houseId) {
        var id = GUID();
        currtWind = openWind('../InfoCollection/AddHouseDistrictImageForm.aspx?houseId=' + houseId, id, '添加小区院落图片', 502, 500, 'new_tab')
    },
    //修改商业店铺图片
    onEditBusinessImageClick: function (houseId) {
        var node = checkGridSelected(this);
        if (node) {
            if (node.length > 1) {
                showErrorMessage("操作失败", "只能选择一条数据进行编辑", "");
            } else {
                var fId = node[0].get('Id');
                var id = GUID();
                currtWind = openWind('../InfoCollection/AddBusinessImageForm.aspx?id=' + fId, id, '修改商业店铺图片', 502, 500, null);
            }
        }
    },
    //修改小区院落图片
    onEditHouseDistrictClick: function (houseId) {
        var node = checkGridSelected(this);
        if (node) {
            if (node.length > 1) {
                showErrorMessage("操作失败", "只能选择一条数据进行编辑", "");
            } else {
                var fId = node[0].get('Id');              
                var id = GUID();
                currtWind = openWind('../InfoCollection/AddHouseDistrictImageForm.aspxid=' + fId, id, '编辑人员', 502, 500, null);
            }
        }
    },
     //删除
    onDeleteBusinessClick: function () {
        var grid = this;
        var node = checkGridSelected(this);
        if (node) {
            Ext.Msg.confirm('提示', '确认要删除选中的数据吗？', function (btn) {
                if (btn == 'yes') {
                    Ext.Msg.wait('正在删除数据，请稍候……', '删除数据');
                    var fIds = getIdFromGrid(node, 'Id');
                    ajaxCalled(null, '../Service/BusinessService.aspx?Action=DeleteImage', fIds, grid, null);
                }

            })
        }
    },
     //删除
    onDeleteHouseClick: function () {
        var grid = this;
        var node = checkGridSelected(this);
        if (node) {
            Ext.Msg.confirm('提示', '确认要删除选中的数据吗？', function (btn) {
                if (btn == 'yes') {
                    Ext.Msg.wait('正在删除数据，请稍候……', '删除数据');
                    var fIds = getIdFromGrid(node, 'Id');
                    ajaxCalled(null, '../Service/HouseDistrictService.aspx?Action=DeleteImage', fIds, grid, null);
                }

            })
        }
    },
    onUpdataBusinessImageClick: function () {
        this.store.removeAll();
        this.store.proxy.conn = { method: 'post', url: this.url };
        this.store.load({ params: { start: 0, limit: this.paperBar.getPageNumber(), dir: '', sort: ''} });
    }
});